package org.hhchat.leetcode.string;

/**
 * Created this one by HMH on 2017/5/30.
 */
public class code434 {

    public static class Solution {
        public int countSegments(String s) {
            int count = 0;
            boolean flag = false;
            for (char c : s.toCharArray()) {
                if(!Character.isSpaceChar(c)){
                    flag = true;
                    continue;
                }
                if (flag) {
                    count++;
                    flag=false;
                }
            }
            if(flag)
                count++;
            return count;
        }
    }

    public static void main(String[] args){
        String s = new String("Hello, my name is John");
        Solution solution = new Solution();
        System.out.println(solution.countSegments(s));
    }

}
